package com.cf.game.im.config;

import com.cf.game.GameCommonProperty;
import com.cf.game.im.ChatVerticle;
import com.cf.game.im.HelloMsgService;
import lombok.extern.slf4j.Slf4j;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * boot-awm-Config
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/27 下午 04:10
 */
@Slf4j
@Configuration
@EnableConfigurationProperties({ImSystemProperty.class, GameCommonProperty.class})
public class ImConfig {

    @Autowired
    private ImSystemProperty imSystemProperty;

    @Autowired
    private GameCommonProperty gameCommonProperty;

    @Bean
    @ConditionalOnMissingBean(ZkClient.class)
    public ZkClient zkClient() {
        log.info("实例化默认的zkClient");
        return new ZkClient(gameCommonProperty.getZookeeper());
    }

    @Bean
    public HelloMsgService helloMsgService() {
        log.info("实例化默认的HelloMsgService");
        return new HelloMsgService();
    }


    @Bean
    @Scope("prototype")
    public ChatVerticle chatVerticle() {
        log.info("实例化默认的ChatVerticle");
        return new ChatVerticle();
    }


}
